package www.openteam.com.model.realtime;

import android.support.annotation.NonNull;

import java.util.List;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.DeliverGoods;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2016/12/23.
 */

public class DeliverGoodsModel extends BaseModel {

    private boolean isQuerySuccess = false;

    public boolean queryDeliverGoods(@NonNull String rdsno,
                                      @NonNull String custid,
                                      long startDate,
                                      long endDate,
                                     String stype,
                                     String moreCom,
                                     int userId,
                                     String jMark,
                                      @NonNull int PageSize,@NonNull final
                                     DeliverGoodsOnListener deliverGoodsOnListener) {
            if (deliverGoodsOnListener == null) {
                throw new RuntimeException("deliverGoodsOnListener不能为空");
            }
                httpApiService.queryDeliverGoods(rdsno,custid,startDate,endDate,stype,moreCom,userId,jMark,PageSize)
                        .compose(new CommonTransformer<DeliverGoods>())
                        .subscribe(new CommonSubscriber<DeliverGoods>(OTApplication.getmContext()) {
                            @Override
                            public void onNext(DeliverGoods deliverGoods) {
                                    isQuerySuccess= true;
                                    deliverGoodsOnListener.queryDGSuccess(deliverGoods.getData());
                            }

                            @Override
                            protected void onError(ApiException e) {
                                super.onError(e);
                                isQuerySuccess =false;
                                deliverGoodsOnListener.queryDGFail(e.message);
                            }
                        });
        return isQuerySuccess;
    }


    //通过接口产生信息回调
    public interface  DeliverGoodsOnListener{

             void queryDGSuccess(List<DeliverGoods.DataEntity> data);

             void queryDGFail(String failMsg);
    }


}
